<template>
  <div class="pinia-demo">
    <h3>pinia-demo</h3>
    <div class="demo-item">
      <h4>store.xxx 直接赋值</h4>
      <h6>{{ counter.double }}</h6>
      <button @click="counter.increment">count +2</button>
    </div>
    <div class="demo-item">
      <h4>使用storeToRefs解构赋值</h4>
      <h6>{{ count }}</h6>
      <h5>(count累加1)</h5>
    </div>
    <div class="demo-item">
      <h4>在actions里面再自调actions</h4>
      <h6>{{ count }}</h6>
      <button @click="counter.logCount">console.log</button>
    </div>
    <div class="demo-item">
      <h4>counter 里调 number</h4>
      <h6>getters: {{ counter.replaceTel }}</h6>
      <h6>actions(num+count): {{ counter.showNum }}</h6>
      <button @click="counter.increNum">num +20</button>
    </div>
  </div>
  <VuexDemo />
</template>

<script>
import { useCounterStore } from '@/store'
import { storeToRefs } from 'pinia'
import VuexDemo from './components/VuexDemo'

export default {
  name: 'App',
  components: {
    VuexDemo
  },
  setup () {
    const counter = useCounterStore()
    const { count } = storeToRefs(counter)

    return {
      counter,
      count,
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
  display: flex;
  justify-content: space-between;
}
#app > div {
  flex: 1;
}
h4 {
  color: red;
}
</style>
